package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DMaterialCostDao;
import com.hongxun.modules.bss.entity.DMaterialCostEntity;
import com.hongxun.modules.bss.service.DMaterialCostService;



@Service("dMaterialCostService")
public class DMaterialCostServiceImpl implements DMaterialCostService {
	@Autowired
	private DMaterialCostDao dMaterialCostDao;

	@Override
	public DMaterialCostEntity queryObject(String guid){
		return dMaterialCostDao.queryObject(guid);
	}
	
	@Override
	public List<DMaterialCostEntity> queryList(Map<String, Object> map){
		return dMaterialCostDao.queryList(map);
	}


	@Override
	public int queryTotal(Map<String, Object> map){
		return dMaterialCostDao.queryTotal(map);
	}
	
	@Override
	public void save(DMaterialCostEntity dMaterialCost){
        if(dMaterialCost.getGuid()==null||dMaterialCost.getGuid().equals("")) {

		    dMaterialCost.setGuid(UUID.randomUUID().toString());
        }
		dMaterialCostDao.save(dMaterialCost);
	}
	
	@Override
	public void update(DMaterialCostEntity dMaterialCost){
		dMaterialCostDao.update(dMaterialCost);
	}
	
	@Override
	public void delete(String guid){
		dMaterialCostDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		dMaterialCostDao.deleteBatch(guids);
	}
	@Override
	public void deleteBatchByMBguid(String[] guids){
		dMaterialCostDao.deleteBatchByMBguid(guids);
	}
	@Override
	public void insertOrReplaceOrDelete(List<DMaterialCostEntity> entities) {
		for (DMaterialCostEntity d : entities) {
			if (d.getMCDatastate().equals("删除")) {
				dMaterialCostDao.delete(d.getGuid());
			} else {
				DMaterialCostEntity dMaterialCostEntity = dMaterialCostDao.queryObject(d.getGuid());
				if (dMaterialCostEntity == null) {
					dMaterialCostDao.save(d);
				} else {
					dMaterialCostDao.update(d);
				}
			}
		}
	}
}
